package com.lsw.jgyf.inject.modules;


import com.lsw.jgyf.components.retrofit.factory.GsonDConverterFactory;
import com.lsw.jgyf.httpapi.HttpService;
import com.lsw.jgyf.inject.Constants;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;

/**
 * author：lsw
 */
@Module
public class ApiModule {

    @Provides
    @Singleton
    public HttpService providesLoginService(OkHttpClient okHttpClient) {
        return getDefaultRetrofit(okHttpClient).create(HttpService.class);
    }

    private Retrofit getDefaultRetrofit(OkHttpClient okHttpClient) {
        return new Retrofit.Builder()
                .baseUrl(Constants.HOST)
                .client(okHttpClient)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonDConverterFactory.create())
                .build();
    }

}
